import 'package:flutter/material.dart';

class RadioPage extends StatefulWidget {
  RadioPage({Key key}) : super(key: key);

  @override
  _RadioPageState createState() => _RadioPageState();
}

class _RadioPageState extends State<RadioPage> {

  var sex = 1;
  var flag = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('单选按钮演示页面'), 
      ), 
      body: Column(
        children: <Widget>[
          // Row(
          //   mainAxisAlignment: MainAxisAlignment.center,
          //   children: <Widget>[
          //     Text('男'),
          //     Radio(
          //       value: 1, 
          //       groupValue: this.sex, 
          //       onChanged: (value){
          //         setState(() {
          //           this.sex = value;
          //         });
          //       }
          //     ),
          //     SizedBox(width: 20),
          //     Text('女'),
          //     Radio(
          //       value: 2, 
          //       groupValue: this.sex, 
          //       onChanged: (value){
          //         setState(() {
          //           this.sex = value;
          //         });
          //       }
          //     )
          //   ], 
          // ),
          // Row(
          //   mainAxisAlignment: MainAxisAlignment.center,
          //   children: <Widget>[
          //     Text("${this.sex}"),
          //     Text(this.sex==1?'男':'女')
          //   ],
          // ),
          SizedBox(height: 40),
          RadioListTile(
            value: 1, 
            groupValue: this.sex, 
            onChanged: (val){
              setState(() {
                this.sex = val;
              });
            },
            title: Text('标题'),
            subtitle: Text('这是一个二级标题'),
            secondary: Icon(Icons.help),
            selected: this.sex==1,
          ),
          RadioListTile(
            value: 2, 
            groupValue: this.sex, 
            onChanged: (val){
              setState(() {
                this.sex = val;
              });
            },
            title: Text('标题'),
            subtitle: Text('这是一个二级标题'),
            secondary: Image.network('https://www.itying.com/images/flutter/1.png'),
            selected: this.sex==2,
          ),
          SizedBox(height: 40),
          Switch(
            value: this.flag, 
            onChanged: (val) {
              setState(() {
                print(val);
                this.flag = val;
              });
            }
          )
        ], 
      ),
    );
  }
}